package com.qf.application.commons.utils;

import lombok.Data;

import java.util.HashMap;

@Data
public class R extends HashMap {

    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    // 返回成功
    public static R ok() {
        R r = new R();
        r.put("code",200); // 200代表成功
        return r;
    }

    // 返回成功带数据
    public static R ok(Object data) {
        R success = ok();
        success.put("data",data);
        return success;
    }

    public static R error() {
        R r = new R();
        r.put("code",500);
        return r;
    }

    public static R error(String msg) {
        R error = error();
        error.put("msg",msg);
        return error;
    }

    public static R write(Boolean flag) {
        if (flag) {
            return ok();
        }
        return error();
    }

}
